package com.eastfair.projectcore.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.projectcore.entity.Dictionary;
import com.eastfair.projectcore.entity.DictionaryType;
import com.eastfair.projectcore.dto.DictionaryTypeSaveDTO;
import com.eastfair.projectcore.dto.DictionaryTypeUpdateDTO;
import com.eastfair.projectcore.dto.DictionaryTypePageQuery;
import com.eastfair.projectcore.service.DictionaryTypeService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author ligang
 * @date 2022-07-14
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/dictionaryType")
@Api(value = "DictionaryType", tags = "")
public class DictionaryTypeController extends SuperController<DictionaryTypeService, Long, DictionaryType, DictionaryTypePageQuery, DictionaryTypeSaveDTO, DictionaryTypeUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<DictionaryType> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<DictionaryType> dictionaryTypeList = list.stream().map((map) -> {
            DictionaryType dictionaryType = DictionaryType.builder().build();
            //TODO 请在这里完成转换
            return dictionaryType;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(dictionaryTypeList));
    }


    /**
     * 分组查询类型
     *
     * @return 查询结果
     */
    @ApiOperation(value = "分组查询类型", notes = "分组查询类型")
    @GetMapping("/queryDictType")
    public R<List<DictionaryType>> queryDictGroupType() {
        QueryWrapper<DictionaryType> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DictionaryType::getIsDeleted, BusinessConstant.DELETE_NO);
        return success(baseService.list(queryWrapper));
    }

}
